package tags;

import dao.tro.Flight;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.TagSupport;

public class InsertSingleFlight extends TagSupport {
    private Flight flight;
    private String change;

    public Flight getFlight() {
        return flight;
    }

    @Override
    public void release() {
        setFlight(null);
        super.release();
    }

    @Override
    public int doStartTag() {
        return EVAL_BODY_INCLUDE;
    }

    @Override
    public int doEndTag() throws JspException {
        try {
            if ((getChange()!=null)&&(getChange().equals("true"))) {
                pageContext.include("../Templates/ChangeFlight.jsp");
            } else {
                pageContext.setAttribute("singleFlight", flight, PageContext.REQUEST_SCOPE);
                pageContext.include("../Templates/Flight.jsp");
            }
        } catch (Exception e) {
            throw new JspException(e.getMessage());
        }
        return EVAL_PAGE;
    }

    public void setFlight(Flight flight) {
        this.flight = flight;
    }

    public String getChange() {
        return change;
    }

    public void setChange(String change) {
        this.change = change;
    }
}
